package com.hnas.eCard.dao.impl;

import java.util.Date;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import com.hnas.core.dao.BaseDaoImpl;
import com.hnas.core.util.DateUtil;
import com.hnas.core.util.StringUtil;
import com.hnas.eCard.dao.CommoditDetailReDao;
import com.hnas.eCard.orm.CommoditDetailRe;

@Component("commoditDetailReDao")
public class CommoditDetailReDaoImpl extends BaseDaoImpl<CommoditDetailRe> implements CommoditDetailReDao{

	public CommoditDetailReDaoImpl() {
		super(CommoditDetailRe.class);
	}

	@Override
	public CommoditDetailRe saveOrUpdate(CommoditDetailRe vo) throws Exception {
		CommoditDetailRe temp = null;
		if(null != vo){
			if(StringUtil.isNotEmpty(vo.getId())){
				temp = this.find(vo.getId());
			}
			if(null == temp){
				temp = vo;
				temp.setCreateTime(DateUtil.dateTimeToString(new Date()));
				temp.setUpdateTime(DateUtil.dateTimeToString(new Date()));
				temp.setIsDeleted(false);
				this.persist(temp);
			}else{
				BeanUtils.copyProperties(vo, temp,new String[]{"id", "createTime"});
				temp.setUpdateTime(DateUtil.dateTimeToString(new Date()));
				this.merge(temp);
			}
		}
		return temp;
	}

}
